package com.wm.task2.util;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ManageFile {

    public static void writerFile(String path, String data, boolean append) {
        try (FileWriter fileWriter = new FileWriter(path, append);) {
            fileWriter.write(data);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String readFile(String path) {

        String result = "";
        try (FileReader fileReader = new FileReader(path);) {
            while (true) {
                int code = fileReader.read();
                if (code == -1) {
                    break;
                }
                result += (char) code;
            }

        } catch (IOException e) {

        }
        return result;
    }

    public static File getFile(String path) {
        File file = new File(path);
        return file;

    }
}
